<template>
  <div class="dialog">
    <el-dialog
      :title="title"
      :visible.sync="visible"
      :close-on-click-modal="false"
      width="45%"
      top="20vh"
      @close="closeDialog"
    >
      <el-form
        :model="createForm"
        label-width="160px"
        label-suffix=":"
        class="searchw"
        ref="createForm"
        :rules="rule"
      >
        <el-row :gutter="24">
          <el-col :span="22">
            <el-form-item label="车系名称" prop="name">
              <el-input
                v-model.trim="createForm.name"
                placeholder="请输入车系名称"
                :disabled="title == '车系详情'"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="22">
            <el-form-item label="生产商" prop="makeName">
              <el-input
                v-model.trim="createForm.makeName"
                placeholder="请输入生产商"
                :disabled="title == '车系详情'"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="22">
            <el-form-item label="品牌名称" prop="name">
              <el-select
                v-model="createForm.letterId"
                size="small"
                filterable
                placeholder="请选择品牌"
                :disabled="title == '车系详情'"
              >
                <el-option
                  v-for="item in brands"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" v-if="title != '新增车系'">
          <el-col :span="22">
            <el-form-item label="采集时间" prop="gatherTime">
              <el-input
                v-model.trim="createForm.gatherTime"
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="closeDialog()">关 闭</el-button>
        <el-button
          type="primary"
          @click="confirmData('createForm')"
          v-if="title != '车系详情'"
          >保 存</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  name: 'addBrand',
  props: {
    row: {
      type: Object,
      default: {}
    },
    title: {
      type: String,
      default: ''
    },
    value: {
      type: Boolean,
      default: false
    },
    brands: {
      type: Array,
      default: []
    }
  },
  data() {
    return {
      visible: true,
      createForm: {
        id: "",
        letterId: "",
        makeName: '',
        name: '',
      },
      rule:{
        name: [
          { required: true, message: '请输入车系名称', trigger: 'blur' },
        ],
        makeName: [
          { required: true, message: '请输入生产商', trigger: 'blur' },
        ],
        letterId:[
          { required: true, message: '请选择品牌', trigger: 'change' },
        ]
      }
    }
  },
  created() {
    if(this.row.id){
      this.createForm = this.row
    }
  },
  mounted() {},
  methods: {
    confirmData(formName) {
      this.$refs[formName].validate((valid) => {
        if(valid) {
          this.$emit('ok', this.createForm)
        }
      })
    },
    closeDialog() {
      this.$emit('cancle')
    }
  }
}
</script>
<style scoped lang="less">
.el-select,.el-input-number,.el-cascader--medium {
  width: 100%!important;
  /deep/.el-input{
    width: 100%!important;
  }
}
</style>
